<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>注册</title>
    <script src="__INDEX__/js/mui.min.js"></script>
    <link href="__INDEX__/css/mui.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="__INDEX__/css/iconfont.css" />
    <link rel="stylesheet" href="__INDEX__/css/style.css" />
    <link rel="stylesheet" href="__INDEX__/css/yund.css" />
</head>

<body>
	<header class="mui-bar mui-bar-nav">
	    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
	    <h1 class="mui-title">注册</h1>
	</header>
	<div class="mui-content login_con">
		<div class="login_top" ><img src="__INDEX__/logo.png" style="width: 120px;padding: 0px;"></div>
		<form id="my_form" class="login_formbox">
			<input id="fromuid" name="fromuid" type="hidden" class="mui-input-clear mui-input">
			<div class="mui-input-row">
				<label><span class="iconfont icon-msnui-caller"></span></label>
				<input id="mobile" name="mobile" type="text" class="mui-input-clear mui-input" placeholder="请输入电话号码" data-input-clear="1"><span class="mui-icon mui-icon-clear mui-hidden"></span>
			</div>
			<div class="mui-input-row fl_yanzm">
				<div class="left clearfix">
					<label><span class="iconfont icon-xiugaimima"></span></label>
					<input id="yzm" name="yzm" type="text" class="mui-input-clear mui-input" placeholder="请输入验证码" data-input-clear="2"><span class="mui-icon mui-icon-clear mui-hidden"></span>
				</div>
				<a href="javascript:;" id="send_code">获取验证码</a>
			</div>
			<div class="mui-input-row" style="color: #FFFFFF;">
					<label><input type="checkbox"  checked="checked" id="zc"/></label>
					我已阅读并同意<a href="{:url('index/xy')}">《注册协议》</a>
				</div>
			<div class="mui-input-row">
				<label><span class="iconfont icon-xiugaimima"></span></label>
				<input id="pwd" name="password" type="password" class="mui-input-clear mui-input" placeholder="请输入密码" data-input-clear="3"><span class="mui-icon mui-icon-clear mui-hidden"></span>
			</div>
		</form>
		<div class="link_area">
			<a class="flogin" href="{:url('index/login')}">登录</a>
			<a href="{:url('index/forget')}">忘记密码</a>
		</div>
		<div class="mui-content-padded">
			<button id='btn' class="mui-btn mui-btn-block login_btn">登 录</button>
		</div>
	</div>
</body>
</html>
{include file="public/footer" /}
<script type="text/javascript" src="__PUBLIC__/static/js/assist.js"></script>
<script>
	var onoff = true;
	//获取验证码
	$('#send_code').click(function() {
		//false就不能发送
		if(!onoff) {
			return;
		}
		onoff = false;
		//点击玩按钮干什么?
		//发验证码? 
		// 1-给谁发? 手机号码
		var phone = $("#mobile").val();
		
		if(phone == '') {
			layer.msg('手机号码不能为空');
			onoff = true;
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		$.ajax({
			type:"post",
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: "{:url('index/index/verify_code')}",
			//请求的过程中传递过去的参数 json
			data: {
				mobile: phone,
			},
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg);
				var num = 60;
				var timer = setInterval(function() {
					num--;
					if(num == 0) {
						$('#send_code').text('发送验证码');
						onoff = true;
						//定时器停了
						clearInterval(timer);
					} else {
						$('#send_code').text(num + 'S');
					}
				}, 1000); // 1000 毫秒==1秒
			}
		})
	});
	
	
	//提交请求
	$('#btn').click(function() {
		var phone = $("#mobile").val();
		var input_code = $("#yzm").val();
		var pwd = $("#pwd").val();
		
		if(phone == '') {
			layer.msg('手机号码不能为空');
			return;
		}
		var reg = /^1[3|4|5|7|8][0-9]{9}$/; //验证规则
		if(!reg.test(phone)) {
			layer.msg('手机号码格式不正确');
			onoff = true;
			return;
		}
		if(input_code.trim() == '') {
			layer.msg('验证码不能为空');
			return;
		}
		if(pwd.trim() == '') {
			layer.msg('密码不能为空');
			return;
		}
		btn.disabled = true;
		setTimeout(function() {
			btn.disabled = false;
		}, 1500);
		
		//推荐人id
		$("#fromuid").val(getUrlParam('fromuid'));
		
		//写入数据库
		$.ajax({
			type:"post",
			//请求的url
			//注意，如果我们使用路由器的情况下，我们需要设置一下本地服务器的ip地址
			url: "{:url('index/index/regist')}",
			//请求的过程中传递过去的参数 json
			data: $('#my_form').serialize(),//表单数据
			//成功了的回调，并且带有返回值
			success: function(data) {
				layer.msg(data.msg, {
				  icon: 1,
				  time: 1500 //2秒关闭（如果不配置，默认是3秒）
				}, function(){
					  if(data.code == 1) {
							location.href = data.url
					  }
				}); 
			}
		})
	});
</script>
